<?php

declare(strict_types=1);

namespace Zyucv7\Components\DataAccess\Services;

use Zyucv7\Components\DataAccess\Projs\Summary as SummaryModel;
use Zyucv7\Components\DataAccess\Projs\Team as TeamModel;
use Zyucv7\Core\View\View;

/**
 * 专家任务表
 */
class Work
{

    private $view;

    public function __construct()
    {
        $this->view = new View(__DIR__ . '/tmpls');
    }

    // 获取专家任务情况，返回文本
    public function getTaskInfo($params)
    {
        $model = new SummaryModel();

        $query = $model->groupTypes();
        if (isset($params['city'])) {
            $tmodel = new TeamModel();
            $row = $tmodel->getByName($params['city']);
            $query->where('team_id', '=', $row['id']);
        }
        if (isset($params['time_range'])) {
            $time_range = $params['time_range'];
            $query->whereBySql('(rwksrq BETWEEN ? AND ?)', [$time_range[0], $time_range[1]]);
            $this->view->with('start_date', $time_range[0]);
            $this->view->with('end_date', $time_range[1]);
        }

        $all = $query->getAll();
        // print_r($all);
        // $query->order('exp_task.assign_time', 'DESC');
        $this->view->with('rows', $all);
        $this->view->with('city', $params['city']?? '');
        return $this->view->render('wweek');

    }
}
